package com.lcy.reggie.controller;

/**
 * ======刘春春大帅逼======
 * ******java学习之旅******
 */

import com.lcy.reggie.common.Result;
import com.lcy.reggie.entity.ShoppingCart;
import com.lcy.reggie.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购物车管理
 */
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;


    /**
     * 选中商品+1
     * @param shoppingCart
     * @return
     */
    @PostMapping("/add")
    public Result<ShoppingCart> add(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.add(shoppingCart);
    }

    /**
     *  选中商品-1
     * @param shoppingCart
     * @return
     */
    @PostMapping("/sub")
    public Result<ShoppingCart> sub(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.sub(shoppingCart);
    }

    /**
     * 显示购物车数据
     * @return
     */
    @GetMapping("/list")
    public Result<List<ShoppingCart>> listResult(){
        return shoppingCartService.listResult();
    }

    /**
     * 清空购物车
     */
    @DeleteMapping("/clean")
    public Result<String> clean(){
        return shoppingCartService.clean();
    }
}
